package com.lucksoft.core.response;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lucksoft.core.constant.BaseOperateConstant;

import lombok.Data;

/**
 * Global Restful Return （统一返回结构）
 * 
 * @author Jonny
 *
 */
@Data
public class ApiResult {

	public ApiResult(int code, String msg, Object data) {
		super();
		this.code = code;
		this.msg = msg;
		this.data = data;	
//		this.list = new ArrayList<Object>();
//		this.detail = new HashMap<Object,Object>();
	}
	
	public ApiResult() {
		this(BaseOperateConstant.SUCCESS_CODE,BaseOperateConstant.SUCCESS_MSG,null);
	}
	
	public static ApiResult error() {
		ApiResult result = new ApiResult();
		result.setCode(BaseOperateConstant.FAILURE_CODE);
		result.setMsg(BaseOperateConstant.FAILURE_MSG);
		
		return result;
	}

	/**
	 * 1正常 0 异常
	 */
	private int code;
	/**
	 * 对错误的具体解释
	 */
	private String msg;
	/**
	 * 返回的结果包装在value中，value可以是单个对象
	 */
	private Object data;
	
	private long count;
	
	private Object mainInfo;
	
	/**
	 * 接口返回的对象类型
	 */
	@JsonIgnore
	private Class<?> rtnClassType;
	
	/**
	 * 访问的接口地址
	 */
	private String apiUrl;
	
	/**
	 * 一般信息处理
	 * @param code
	 * @param msg
	 * @param data
	 * @return ApiResult
	 */
	public static ApiResult valueOf(int code, String msg, Object data) {
		return new ApiResult(code, msg, data);
	}

}